﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Prototype
{
    public partial class details : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["AutoFixConnectionString"].ToString());
            StreamReader stepContentReader = null;
            OleDbDataReader dataReader = null;
            string sql = @"SELECT Article.ArticleName, Article.ArticleImageUrl, ApplicationUser.UserName, Article.ArticleID, Step.StepURL, Step.StepName
                        FROM (Article INNER JOIN ApplicationUser ON Article.UserID =  ApplicationUser.UserID) INNER JOIN Step ON Article.ArticleID = Step.ArticleID
                        WHERE Article.ArticleID = @f1";
            OleDbCommand cmd = new OleDbCommand(sql, connection);
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@f1", Request.QueryString["aID"]);
            connection.Open();
            dataReader = cmd.ExecuteReader();
            dataReader.Read();

           
            if(dataReader.HasRows){
                stepContentReader = new StreamReader(Server.MapPath(dataReader.GetValue(4).ToString()));
                this.lblStepTitle.Text = dataReader.GetValue(5).ToString();
                this.lblUserName.Text = dataReader.GetValue(2).ToString();
                this.lblArticleTitle.Text = dataReader.GetValue(0).ToString();
                this.lblStepContent.Text = stepContentReader.ReadToEnd();
                this.imgArticleImage.ImageUrl = dataReader.GetValue(1).ToString();

                stepContentReader = null;
            }
     
        }
    }
}